const { Tray, Menu } = require('electron')

function createTray(app, win) {
  const tray = new Tray('./icon.jpg')
  tray.setToolTip('readit')
  tray.on('click', (e) => {
    if (e.shiftKey) {
      app.quit()
    } else {
      win.isVisible() ? win.hide() : win.show()
    }
  })
  tray.setContextMenu(
    Menu.buildFromTemplate([
      {
        label: '退出',
        click: () => {
          app.quit()
        }
      }
    ])
  )
}

module.exports = createTray
